import QtQuick 2.15
import QtGraphicalEffects 1.15
import App.Global 1.0

//最小化，mini化，最大化，关闭
Item{
    id:topRect
    //设置鼠标双击
    MouseArea{
        anchors.fill: parent
        acceptedButtons:Qt.LeftButton
        //双击切换全屏/正常大小
        onDoubleClicked: {
            if(GlobalState.isFull){
                myWindow.width=1317
                myWindow.height=933
                GlobalState.isFull=false
            }else{
                myWindow.x=0
                myWindow.y=0
                myWindow.width=screen.width-1
                myWindow.height=screen.height-1
                GlobalState.isFull=true
            }
        }
        //按住拖动窗口
        property point clickPos:"0,0"
        onPressed: function (mouse) {
            clickPos=Qt.point(mouse.x,mouse.y)
        }
        onPositionChanged: function (mouse) {
            let delta=Qt.point(mouse.x-clickPos.x,mouse.y-clickPos.y)
            myWindow.x+=delta.x
            myWindow.y+=delta.y
        }
    }

    //缩放栏区域的行布局
    Row{
        id:zoomRow
        anchors.verticalCenter:parent.verticalCenter
        anchors.left: parent.left
        spacing: 20
        //mini化窗口
        Image{
            id:miniImg
            width: 25
            height: 25
            anchors.verticalCenter: parent.verticalCenter
            source: "qrc:/res/topArea/mini.png"
            //设置图片变更效果
            layer.enabled: false
            layer.effect: ColorOverlay{
                source: miniImg
                color: GlobalState.uiHoverColor
            }
            //设置鼠标悬停效果
            MouseArea{
                anchors.fill: parent
                hoverEnabled: true
                cursorShape:Qt.PointingHandCursor
                onEntered: {
                    miniImg.layer.enabled=true
                }
                onExited: {
                    miniImg.layer.enabled=false
                }
                onClicked: {
                    //mini化
                }
            }
        }
        Image{
            id:minimizeImg
            width: 25
            height: 25
            anchors.verticalCenter: parent.verticalCenter
            source: "qrc:/res/topArea/minimize.png"
            //设置图片变更效果
            layer.enabled: false
            layer.effect: ColorOverlay{
                source: minimizeImg
                color: GlobalState.uiHoverColor
            }
            //设置鼠标悬停效果
            MouseArea{
                anchors.fill: parent
                hoverEnabled: true
                cursorShape:Qt.PointingHandCursor
                onEntered: {
                    minimizeImg.layer.enabled=true
                }
                onExited: {
                    minimizeImg.layer.enabled=false
                }
                onClicked: {
                    myWindow.showMinimized()
                }
            }
        }
        //最大化/向下还原
        Image{
            id:maximizeImmg
            width: 25
            height: 25
            anchors.verticalCenter: parent.verticalCenter
            // 根据状态动态切换图标
            source: GlobalState.isFull ? "qrc:/res/topArea/restoreDown.png" : "qrc:/res/topArea/maximize.png"
            //设置图片变更效果
            layer.enabled: false
            layer.effect: ColorOverlay{
                source: maximizeImmg
                color: GlobalState.uiHoverColor
            }
            //设置鼠标悬停效果
            MouseArea{
                anchors.fill: parent
                hoverEnabled: true
                cursorShape:Qt.PointingHandCursor
                onEntered: {
                    maximizeImmg.layer.enabled=true
                }
                onExited: {
                    maximizeImmg.layer.enabled=false
                }
                onClicked: {
                    if(GlobalState.isFull){
                        myWindow.width=1317
                        myWindow.height=933
                        GlobalState.isFull=false
                    }else{
                        myWindow.x=0
                        myWindow.y=0
                        myWindow.width=screen.width-1
                        myWindow.height=screen.height-1
                        GlobalState.isFull=true
                    }
                }
            }
        }
        //关闭
        Image{
            id:closeImg
            width: 25
            height: 25
            anchors.verticalCenter: parent.verticalCenter
            source: "qrc:/res/topArea/close.png"
            //设置图片变更效果
            layer.enabled: false
            layer.effect: ColorOverlay{
                source: closeImg
                color: GlobalState.uiHoverColor
            }
            //设置鼠标悬停效果
            MouseArea{
                anchors.fill: parent
                hoverEnabled: true
                cursorShape:Qt.PointingHandCursor
                onEntered: {
                    closeImg.layer.enabled=true
                }
                onExited: {
                    closeImg.layer.enabled=false
                }
                onClicked: {
                    Qt.quit()
                }
            }
        }
    }

}

